<?php

class Zend_View_Helper_BoldWords extends Zend_View_Helper_Abstract {

    public function boldWords($words, $subject, $el="span", $class="searchhl") {

        preg_match_all("/[А-Яа-я\wрстуфхцчшщьыъэю’\']+/", $words, $match);
        $words = $match[0];
        
        if (is_array($words)) {
//            $result = strtolower($subject);
            $result = $subject;
            foreach ($words as $word) {
                
          
                $result = preg_replace("/($word)+/i", "<" . $el . " class=\"" . $class . "\">" . $word . "</" . $el . ">", $result);
//                $result = str_ireplace($word, "<" . $el . " class=\"" . $class . "\">" . $word . "</" . $el . ">", $result);
            }
            return $result;
        }
    }

}